﻿using System;
using System.Collections.Generic;
using UnityEngine;

namespace ParticlePlayground
{
	// Token: 0x0200014F RID: 335
	[Serializable]
	public class ParticlePlaygroundTrail
	{
		// Token: 0x06000735 RID: 1845 RVA: 0x0002AEC4 File Offset: 0x000290C4
		public ParticlePlaygroundTrail()
		{
			this.UpdateCache();
		}

		// Token: 0x06000736 RID: 1846 RVA: 0x0002AF04 File Offset: 0x00029104
		public ParticlePlaygroundTrail(int pointCache)
		{
			this._pointCache = Mathf.Clamp(pointCache, this.minPointCache, this.maxPointCache);
			this.UpdateCache();
		}

		// Token: 0x06000737 RID: 1847 RVA: 0x0002AF64 File Offset: 0x00029164
		public virtual void UpdateCache()
		{
			this._timeCached = PlaygroundC.globalTime;
			this.meshVerticesCache = new Vector3[this._pointCache * 2];
			this.meshNormalsCache = new Vector3[this._pointCache * 2];
			this.meshUvsCache = new Vector2[this._pointCache * 2];
			this.meshTrianglesCache = new int[(this._pointCache - 1) * 6];
			this.meshColorsCache = new Color32[this._pointCache * 2];
			this._isReady = true;
		}

		// Token: 0x06000738 RID: 1848 RVA: 0x0002AFE4 File Offset: 0x000291E4
		public virtual void UpdateMesh()
		{
			this.trailMesh.Clear();
			this.trailMesh.vertices = this.meshVerticesCache;
			this.trailMesh.uv = this.meshUvsCache;
			this.trailMesh.triangles = this.meshTrianglesCache;
			this.trailMesh.colors32 = this.meshColorsCache;
			this.trailMesh.normals = this.meshNormalsCache;
		}

		// Token: 0x06000739 RID: 1849 RVA: 0x0002B054 File Offset: 0x00029254
		public virtual void RecalculateBounds()
		{
			this.trailMesh.RecalculateBounds();
		}

		// Token: 0x0600073A RID: 1850 RVA: 0x0002B064 File Offset: 0x00029264
		public virtual void ClearMesh()
		{
			this._birthIterator = 0;
			this._deathIterator = 0;
			this.meshVerticesCache = new Vector3[0];
			this.meshNormalsCache = new Vector3[0];
			this.meshUvsCache = new Vector2[0];
			this.meshTrianglesCache = new int[0];
			this.meshColorsCache = new Color32[0];
		}

		// Token: 0x0600073B RID: 1851 RVA: 0x0002B0BC File Offset: 0x000292BC
		public virtual void SetFirstPoint(Vector3 pos, Vector3 dir, float startWidth, float lifetime, float creationTime)
		{
			this._particleDirection = dir;
			this.AddPoint(pos, startWidth, lifetime, creationTime);
			this.AddPoint(pos, startWidth, lifetime, creationTime);
			this._birthIterator = 2;
			this._deathIterator = 0;
		}

		// Token: 0x0600073C RID: 1852 RVA: 0x0002B0EC File Offset: 0x000292EC
		public virtual void SetLastPoint(Vector3 pos, Vector3 dir, float startWidth, float lifetime, float creationTime)
		{
			this._particleDirection = dir;
			this.AddPoint(pos, startWidth, lifetime, creationTime);
			this.Die();
		}

		// Token: 0x0600073D RID: 1853 RVA: 0x0002B108 File Offset: 0x00029308
		public virtual void AddPoint(Vector3 position, float width, float lifetime, float creationTime)
		{
			if (this._birthIterator >= this._pointCache || this._isDead)
			{
				return;
			}
			this.trailPoints.Add(new TrailPoint(position, lifetime, width, creationTime));
			this.AddPoint(position);
		}

		// Token: 0x0600073E RID: 1854 RVA: 0x0002B144 File Offset: 0x00029344
		public virtual void AddPoint(Vector3 position, Vector3 velocity, float width, float lifetime, float creationTime)
		{
			if (this._birthIterator >= this._pointCache || this._isDead)
			{
				return;
			}
			this.trailPoints.Add(new TrailPoint(position, velocity, lifetime, width, creationTime));
			this.AddPoint(position);
		}

		// Token: 0x0600073F RID: 1855 RVA: 0x0002B184 File Offset: 0x00029384
		public virtual void AddPoint(Vector3 position)
		{
			this._lastAddedPointDirection = position - this._previousParticlePosition;
			this._lastAddedPointPosition = position;
			this.meshVerticesCache[this._birthIterator * 2] = position;
			this.meshVerticesCache[this._birthIterator * 2 + 1] = position;
			this.meshNormalsCache[this._birthIterator * 2] = -Vector3.forward;
			this.meshNormalsCache[this._birthIterator * 2 + 1] = -Vector3.forward;
			this.meshUvsCache[this._birthIterator * 2] = new Vector2(1f, 0f);
			this.meshUvsCache[this._birthIterator * 2 + 1] = new Vector2(0f, 1f);
			this.meshColorsCache[this._birthIterator * 2] = default(Color32);
			this.meshColorsCache[this._birthIterator * 2 + 1] = default(Color32);
			if (this.trailPoints.Count > 1)
			{
				int num = this._birthIterator * 2;
				int num2 = (this._birthIterator - 1) * 6;
				this.meshTrianglesCache[num2] = num - 2;
				this.meshTrianglesCache[num2 + 1] = num - 1;
				this.meshTrianglesCache[num2 + 2] = num;
				this.meshTrianglesCache[num2 + 3] = num;
				this.meshTrianglesCache[num2 + 4] = num - 1;
				this.meshTrianglesCache[num2 + 5] = num + 1;
			}
			this.NextPoint();
		}

		// Token: 0x06000740 RID: 1856 RVA: 0x0002B32C File Offset: 0x0002952C
		public virtual void RemovePoint(int index)
		{
			if (this._deathIterator < this._birthIterator - 2)
			{
				this.meshVerticesCache[this._deathIterator * 2] = this.meshVerticesCache[this._deathIterator * 2 + 2];
				this.meshVerticesCache[this._deathIterator * 2 + 1] = this.meshVerticesCache[this._deathIterator * 2 + 3];
				this.meshColorsCache[this._deathIterator * 2] = default(Color32);
				this.meshColorsCache[this._deathIterator * 2 + 1] = default(Color32);
				this._deathIterator++;
			}
		}

		// Token: 0x06000741 RID: 1857 RVA: 0x0002B404 File Offset: 0x00029604
		public virtual void SetColor(int index, Color32 color)
		{
			this.meshColorsCache[index * 2] = color;
			this.meshColorsCache[index * 2 + 1] = color;
		}

		// Token: 0x06000742 RID: 1858 RVA: 0x0002B430 File Offset: 0x00029630
		public virtual void NextPoint()
		{
			this._birthIterator++;
		}

		// Token: 0x06000743 RID: 1859 RVA: 0x0002B440 File Offset: 0x00029640
		public virtual float GetParticleTime()
		{
			return this._particleTime;
		}

		// Token: 0x06000744 RID: 1860 RVA: 0x0002B448 File Offset: 0x00029648
		public virtual void SetParticleTime(float time)
		{
			this._particleTime = time;
		}

		// Token: 0x06000745 RID: 1861 RVA: 0x0002B454 File Offset: 0x00029654
		public virtual Vector3 GetParticlePosition()
		{
			return this._particlePosition;
		}

		// Token: 0x06000746 RID: 1862 RVA: 0x0002B45C File Offset: 0x0002965C
		public virtual void SetParticlePosition(Vector3 position)
		{
			if (this._isDead)
			{
				return;
			}
			this._previousParticlePosition = this._particlePosition;
			this._particlePosition = position;
			this._particleDirection = (position - this._previousParticlePosition).normalized;
		}

		// Token: 0x06000747 RID: 1863 RVA: 0x0002B4A4 File Offset: 0x000296A4
		public virtual void SetParticleDirection(Vector3 direction)
		{
			this._particleDirection = direction;
		}

		// Token: 0x06000748 RID: 1864 RVA: 0x0002B4B0 File Offset: 0x000296B0
		public virtual Vector3 GetLastAddedPointPosition()
		{
			return this._lastAddedPointPosition;
		}

		// Token: 0x06000749 RID: 1865 RVA: 0x0002B4B8 File Offset: 0x000296B8
		public virtual Vector3 GetParticleDirection()
		{
			return this._particleDirection;
		}

		// Token: 0x0600074A RID: 1866 RVA: 0x0002B4C0 File Offset: 0x000296C0
		public virtual Vector3 GetLastAddedPointDirection()
		{
			return this._lastAddedPointDirection;
		}

		// Token: 0x0600074B RID: 1867 RVA: 0x0002B4C8 File Offset: 0x000296C8
		public virtual float GetPathDeviation()
		{
			return Vector3.Angle(this._lastAddedPointDirection, this._particleDirection);
		}

		// Token: 0x0600074C RID: 1868 RVA: 0x0002B4DC File Offset: 0x000296DC
		public virtual int GetBirthIterator()
		{
			return this._birthIterator;
		}

		// Token: 0x0600074D RID: 1869 RVA: 0x0002B4E4 File Offset: 0x000296E4
		public virtual int GetDeathIterator()
		{
			return this._deathIterator;
		}

		// Token: 0x0600074E RID: 1870 RVA: 0x0002B4EC File Offset: 0x000296EC
		public virtual int GetPointCache()
		{
			return this._pointCache;
		}

		// Token: 0x0600074F RID: 1871 RVA: 0x0002B4F4 File Offset: 0x000296F4
		public virtual float TimeCached()
		{
			return this._timeCached;
		}

		// Token: 0x06000750 RID: 1872 RVA: 0x0002B4FC File Offset: 0x000296FC
		public virtual bool CanRemovePoint(int point)
		{
			return this.trailPoints[point].CanRemove();
		}

		// Token: 0x06000751 RID: 1873 RVA: 0x0002B510 File Offset: 0x00029710
		public virtual bool CanRemoveTrail()
		{
			return this.trailPoints.Count != 0 && this._isReady && this.trailPoints[this.trailPoints.Count - 1].CanRemove();
		}

		// Token: 0x06000752 RID: 1874 RVA: 0x0002B54C File Offset: 0x0002974C
		public virtual void WakeUp()
		{
			this._isDead = false;
		}

		// Token: 0x06000753 RID: 1875 RVA: 0x0002B558 File Offset: 0x00029758
		public virtual void Die()
		{
			this._isDead = true;
		}

		// Token: 0x06000754 RID: 1876 RVA: 0x0002B564 File Offset: 0x00029764
		public virtual bool IsDead()
		{
			return this._isDead;
		}

		// Token: 0x0400074A RID: 1866
		[HideInInspector]
		public bool update = true;

		// Token: 0x0400074B RID: 1867
		[HideInInspector]
		public GameObject trailGameObject;

		// Token: 0x0400074C RID: 1868
		[HideInInspector]
		public Transform trailTransform;

		// Token: 0x0400074D RID: 1869
		[HideInInspector]
		public MeshRenderer trailRenderer;

		// Token: 0x0400074E RID: 1870
		[HideInInspector]
		public MeshFilter trailMeshFilter;

		// Token: 0x0400074F RID: 1871
		[HideInInspector]
		public Mesh trailMesh;

		// Token: 0x04000750 RID: 1872
		[HideInInspector]
		public int particleId;

		// Token: 0x04000751 RID: 1873
		[HideInInspector]
		public int minPointCache = 2;

		// Token: 0x04000752 RID: 1874
		[HideInInspector]
		public int maxPointCache = 32767;

		// Token: 0x04000753 RID: 1875
		[NonSerialized]
		public List<TrailPoint> trailPoints = new List<TrailPoint>();

		// Token: 0x04000754 RID: 1876
		[NonSerialized]
		public Vector3[] meshVerticesCache;

		// Token: 0x04000755 RID: 1877
		[NonSerialized]
		public Vector3[] meshNormalsCache;

		// Token: 0x04000756 RID: 1878
		[NonSerialized]
		public Vector2[] meshUvsCache;

		// Token: 0x04000757 RID: 1879
		[NonSerialized]
		public int[] meshTrianglesCache;

		// Token: 0x04000758 RID: 1880
		[NonSerialized]
		public Color32[] meshColorsCache;

		// Token: 0x04000759 RID: 1881
		protected int _pointCache = 200;

		// Token: 0x0400075A RID: 1882
		protected int _birthIterator;

		// Token: 0x0400075B RID: 1883
		protected int _deathIterator;

		// Token: 0x0400075C RID: 1884
		protected float _particleTime;

		// Token: 0x0400075D RID: 1885
		protected Vector3 _particlePosition;

		// Token: 0x0400075E RID: 1886
		protected Vector3 _previousParticlePosition;

		// Token: 0x0400075F RID: 1887
		protected Vector3 _particleDirection;

		// Token: 0x04000760 RID: 1888
		protected Vector3 _lastAddedPointPosition;

		// Token: 0x04000761 RID: 1889
		protected Vector3 _lastAddedPointDirection;

		// Token: 0x04000762 RID: 1890
		protected bool _isDead;

		// Token: 0x04000763 RID: 1891
		protected bool _isReady;

		// Token: 0x04000764 RID: 1892
		protected float _timeCached;
	}
}
